/**
 * 签到页面
 * author:yinht
 * date:2017年6月2日19:30:42
 */
;
define(function(require, exports, module) {
	var wechat = require("wechat");

	var newfollow = {
		/**
		 * bindEvent 页面事件
		 */
		bindEvent: function() {
			//返回
			$("#return_newfollow").unbind().on("click", function() {
				window.history.back(-1);
			});
			$("#new_follow").unbind().on("click", function() {
				newfollow.sendParam();
			});
			$("#follow_style").unbind().on("click", function() {
				//初始化信息
				var initializestr = window.localStorage.getItem("initialize");
				var initializeObj = JSON.parse(initializestr);
				var picker = new mui.PopPicker();
				var styleArray = [];
					for(var i = 0; i < initializeObj.contactWay.length; i++) {
						var item = {
							value: initializeObj.contactWay[i].pk_defdoc,
							text: initializeObj.contactWay[i].name
						}
						styleArray.push(item);
					}
					picker.setData(styleArray);

					picker.show(function(selectItems) {
						$("#follow_style").val(selectItems[0].text);
						$("#follow_style").attr("gjstyle", selectItems[0].value);
					picker.dispose();
					console.log(selectItems);
				}, function(selectItems) {
					picker.dispose();
				});
			});
		},
		/**
		 * 进行页面路由监听配置
		 * 
		 */
		bindRout: function() {
			//公共页面监听路由
			Path.map("#/index/:page_name").to(function() {
				console.log(this.params["page_name"]);
				var page_name = this.params["page_name"];
				var from = "right"; //从右边过来
				if(page_name == "memberShip"){
					from = "left";
				}else{
					from = "right";
				}
				//记录状态
				common.loadPage({
					pageUrl: "html/" + page_name + ".html",
					reload: true,
					from: from
				});
			});
			Path.listen();
		},

		/**
		 * 页面数据加载
		 */
		loadData: function() {
			var userInfo = window.localStorage.getItem("userInfo");
			var name = JSON.parse(userInfo);
			$(".khname").text(name.data.docker);
			console.log(name);
		},
		sendParam: function(){
			var pk_member = window.localStorage.getItem("pk_member");
			var pk_user = window.localStorage.getItem("pk_user");
			var name = $(".khname").text();
			var gjstyle = $("#follow_style").attr("gjstyle");
			var myDate = new Date();
			var year = myDate.getFullYear();
			var month = myDate.getMonth()+1;
			var date = myDate.getDate(); 
			var hours = myDate.getHours(); 
			var mimutes = myDate.getMinutes();
			 if (mimutes >= 0 && mimutes <= 9) {
				 mimutes = "0" + mimutes;
			    }
			var seconds = myDate.getSeconds();
			if (seconds >= 0 && seconds <= 9) {
				seconds = "0" + seconds;
		    }
			var time = year +"-"+ month +"-"+ date+" "+ hours +":"+ mimutes +":"+ seconds;
			var gjdetails = $(".details_con").val();
			param = {
					pk_user: pk_user,
					pk_member: pk_member,
					name: name,
					time: time,
					gjstyle: gjstyle,
					gjdetails: gjdetails
       			}

			common.loadData({
				url: "/service/RRTPubServlet?method=sendRemind", //"/UMPPubServlet?method=getWxUserInfo",
				param: param,
				successCallBack: newfollow.sendRemindCallBack, //回调函数
				loadAll: newfollow.loadedAllFlag,
				cache: false
			});
			console.log(param);
		},
		sendRemindCallBack: function(json){
			console.log(JSON.stringify(json));
			if(json.status == "0") {
				common.showTip({
				    time:3000,
				    content:"提交跟进成功！",
				    callback:function(){
				    	window.history.back(-1);
					    	//common.showTip({content:"我已经关闭"});
					    }
				});
				return ;
				
			} else {
				common.showTip({
					content: json.message
				});
			}
		},
		/**
		 * each page init mothed
		 */
		initialize: function() {

			this.loadData();
			//事件绑定
			this.bindEvent();
			//路由绑定
			this.bindRout();
		}
	};

	module.exports = newfollow;
});

